import re

ifconfig = '''ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.50.175  netmask 255.255.255.0  broadcast 192.168.50.255
        inet6 fe80::250:56ff:feab:b5b7  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:ab:b5:b7  txqueuelen 1000  (Ethernet)
        RX packets 1591  bytes 204304 (199.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1075  bytes 96081 (93.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0'''

re_findall_result = re.findall('(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})',ifconfig)


for ip in re_findall_result:
    if ip.split('.')[-1] == '0':#最开始写成了0，一直无法匹配出来。这是字符串类型，不是数字类型。
        mask = ip
    elif ip.split('.')[-1] == '255':
        broadcast = ip
    else:
        ipv4_ip = ip

print('{0:<15} : {1:<10}'.format('Network Mask',mask))
print('{0:<15} : {1:<10}'.format('Broadcast',broadcast))
print('{0:<15} : {1:<10}'.format('IPv4 Addr',ipv4_ip))